package javacore.v1ch6;

import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class FunctionInterTest {

    public static void main(String[] args) {
       test1();
    }

    public static void mainTest () {
        int[] nums = {1, 100, 22, 1223, 123};

//        Supplier<Integer> supplier = () -> {
//
//            int max = 0;
//            for (int i : nums
//            ) {
//                max = i > max ? i : max;
//            }
//            return max;
//        };
//        System.out.println(supplier.get());

        Consumer<String> consumer1 = (String s) -> {
            System.out.println("consumer1" + s);

        };
        consumer1.accept("123");
        consumer1.andThen((some) -> {
            System.out.println("consumer2" + some);
        }).accept("1234");

        Predicate<String> predicate = (s -> {
            return s.equals("123");
        });

        System.out.println(predicate.test("123"));
    }

    /**
     * 方法接口的测试 lambda方法接口参数
     */
    public static void test1() {
        List<Integer> list = new ArrayList<>();

        list.add(1);
        list.add(2);
        list.add(3);

        List resultLst = list.stream().filter(new Predicate<Integer>() {

            @Override
            public boolean test(Integer t) {
                return t > 2;
            }
        }).collect(Collectors.toList());

        System.out.println(resultLst.toString());

        resultLst = list.stream().map(new Function<>() {

            @Override
            public Object apply(Integer integer) {
                return 1;
            }

        }).collect(Collectors.toList());

        System.out.println(resultLst);

        list.stream().forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                System.out.println(integer);
            }
        });
    }


}
